<template>
	<view class="dataCenterMain">
		<view class="dataCenterBox">
			<view class="h3">收益中心</view>
			<view class="dataCenterHeaderBox">
				<view class="headerCardBox">
					<view class="top">
						<view class="tradeNumber">
							{{detailed.total_income? $tools.format(detailed.total_income): "0.00"}}
						</view>
						<view>
							累计收益 (元)
						</view>
						<view @click="listTab" class="detailList flex align-center">
							列表明细
							<image src="../../static/images/icon_sanjiao.png" mode="widthFix"></image>
						</view>
					</view>
					<view class="profit">
						<view class="mouthProfit">
							<text>{{
							  detailed.today_income
							    ? $tools.format(detailed.today_income)
							    : "0.00"
							}}</text>
							<text>今日收益 (元)</text>
						</view>
						<view class="mouthProfit">
							<text>{{detailed.month_income? $tools.format(detailed.month_income): "0.00"}}</text>
							<text>本月收益 (元)</text>
						</view>
					</view>
				</view>
			</view>
			<view class="dataCenterBodyBox">
				<view v-if="unionData.length > 0">
					<!-- <image class="dcArc" src="../../static/images/dcArc.png" mode="widthFix"></image> -->
					<view class="dataCenterBodyItem" v-for="(item, index) in unionData" :key="index">
						<view class="title flex align-center">
							<view class="color" :style="{'background':color[Math.round(Math.random()*3)]}"></view>
							{{ item.name }}
						</view>
						<view class="dataBox flex flex-wrap align-center justify-around">
							<view class="dataItem">
								<text>{{
                  item.tradeIncome ? $tools.format(item.tradeIncome) : "0.00"
                }}</text>
								交易返现
							</view>
							<view class="dataItem">
								<text>{{
                  item.activeIncome ? $tools.format(item.activeIncome) : "0.00"
                }}</text>
								激活返现
							</view>
							<view class="dataItem">
								<text>{{
                  item.groupIncome ? $tools.format(item.groupIncome) : "0.00"
                }}</text>
								团队返现
							</view>
						</view>
					</view>
				</view>
				<view class="noMachine flex align-center" v-if="unionData.length == 0 && isLoad">
					<image src="../../static/images/noData/zwsy.png" mode="widthFix"></image>
					<text>暂无签约机具</text>
				</view>
			</view>
		</view>
		<toast></toast>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				enable: true,
				borderTop: true,
				unionData: {
					// tradeIncome:'0.00',
				},
				detailed: {
					today_income: "0.00",
					month_income: "0.00",
					total_income: "0.00",
				},
				color: ['#ff612b','#f9b525','#30b65f','#6f67bb'],
			isLoad: false,
		};
	},
	onShow() {
			this.enable = true;
			this.getUserIncome();
			this.getProductList();
		},
		onHide() {
			this.enable = false;
		},
		onPullDownRefresh() {
			this.getProductList();
		},
		methods: {
			getProductList() {
				this.$u.api
					.getProductList()
					.then((res) => {
						if (res.status == 200) {
							this.unionData = res.result;
						}
						uni.stopPullDownRefresh();
					})
					.catch((res) => {
						if (res.errMsg == "request:fail timeout") {
							this.$u.toast("请求超时，请重试!");
						} else if (res.errMsg == "request:fail") {
							this.$u.toast("请求失败，请重试");
						} else {
							 this.$u.toast("请求失败，请重试");
						}
						this.$loading(false);
						setTimeout(() => {
							this.$u.route({
								type: "navigateBack",
								delta: 1,
							});
						}, 2000);
					});
			},
			getUserIncome() {
				this.$u.api
					.getUserIncome()
					.then((res) => {
						if (res.status == 200) {
							if (res.result) {
								this.detailed = res.result;
							}
						}
						uni.stopPullDownRefresh();
					})
					.catch((res) => {
						if (res.errMsg == "request:fail timeout") {
							this.$u.toast("请求超时，请重试!");
						} else if (res.errMsg == "request:fail") {
							this.$u.toast("请求失败，请重试");
						} else {
							 this.$u.toast("请求失败，请重试");
						}
						this.$loading(false);
						setTimeout(() => {
							this.$u.route({
								type: "navigateBack",
								delta: 1,
							});
						}, 2000);
					});
			},

			listTab() {
				this.$u.route({
					url: "/pages/sytj/sytj",
					type: "switchTab",
				});
			},
		},
	};
</script>

<style lang="scss">
	page {
		background-color: #f3f3f3;
	}

	.dataCenterBox {
		.h3 {
			padding: 40rpx 0 30rpx 30rpx;
			font-size: 38rpx;
			color: #000;
			font-weight: bold;
			letter-spacing: 2rpx;
		}

		.dataCenterHeaderBox {
			padding: 0 30rpx 20rpx;

			.headerCardBox {
				height: 280rpx;
				// background-image: linear-gradient(to top, #fc6306 0%, #fb4535 100%);
				background: #fff url("../../static/images/bg_card.png") no-repeat;
				background-size: 100% 100%;
				border-radius: 10rpx;
				box-sizing: border-box;
				overflow: hidden;

				.profit {
					padding: 0 42rpx;
					font-size: 34rpx;
					letter-spacing: 3rpx;
					color: #fff;
					margin-top: 30rpx;
					font-family: numberfont;

					&>.mouthProfit:last-child {
						float: left;
						margin-left: 194rpx;
					}

					.mouthProfit {
						float: left;
						display: flex;
						flex-direction: column;

						& text:last-child {
							font-size: 24rpx;
							opacity: 0.8;
							margin-top: 10rpx;
						}
					}
				}

				.top {
					position: relative;
					padding: 32rpx 0 0 36rpx;

					view:nth-of-type(1) {
						font-size: 54rpx;
						font-family: numberFont;
						color: #fff;
						letter-spacing: 2rpx;
					}

					view:nth-of-type(2) {
						color: #fff;
						font-size: 24rpx;
						opacity: 0.8;
						letter-spacing: 2rpx;
						padding-top: 10rpx;
					}

					.detailList {
						position: absolute;
						right: 0;
						top: 36rpx;
						background-color: #fff;
						padding: 14rpx 22rpx;
						color: #fb492f;
						font-size: 24rpx;
						border-top-left-radius: 50rpx;
						border-bottom-left-radius: 50rpx;

						image {
							width: 10rpx;
							height: 12rpx;
							margin-left: 12rpx;
						}
					}
				}

				.sub {
					position: relative;

					.tradeNumber {
						position: absolute;
						left: 40rpx;
						top: 0rpx;
						font-size: 70rpx;
						font-family: "numberFont";
						color: #fff;
						font-weight: bold;
						letter-spacing: 5rpx;
						text-align: center;

						text {
							font-size: 36rpx;
							position: relative;
							top: -4rpx;
						}
					}
				}
			}
		}

		.dataCenterBodyBox {
			padding: 0 30rpx 10rpx;

			.dcArc {
				width: 100%;
				display: block;
			}

			.dataCenterBodyItem {
				padding: 30rpx 0 0 20rpx;
				background-color: #fff;
				margin-bottom: 20rpx;
				height: 250rpx;
				border-radius: 14rpx;

				.title {
					font-size: 32rpx;
					color: #000;
					font-weight: 700;

					.color {
						height: 24rpx;
						width: 8rpx;
						background-color: #0000FE;
						border-radius: 8rpx;
						margin-right: 18rpx;
					}
				}

				.dataBox {
					.dataItem {
						padding-top: 56rpx;
						font-size: 24rpx;
						color: #999;
						text-align: center;

						text {
							font-size: 38rpx;
							color: #000;
							display: block;
							font-family: "numberFont";
							letter-spacing: 2rpx;
							padding-bottom: 18rpx;
						}
					}
				}
			}
		}
	}

	.noMachine {
		padding-top: 60rpx;
		margin-top: 100rpx;
		text-align: center;
		color: #ababab;
		flex-direction: column;

		text {
			margin-top: -40rpx;
		}

		image {
			margin-top: -140rpx;
			width: 380rpx;
		}
	}
</style>
